<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在线课堂</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="网站描述"/>
    <meta name="keywords" content=""/>
    <meta name="author" content="wangl"/>
    <link rel="icon" href="http://ow9lg82yy.bkt.clouddn.com/24f5c360-485d-4a6d-9468-2a61c353cf37.ico">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <style type="text/css">
        .layui-form-item .layui-inline {
            width: 33.333%;
            float: left;
            margin-right: 0;
        }

        @media (max-width: 1240px) {
            .layui-form-item .layui-inline {
                width: 100%;
                float: none;
            }
        }

        .layui-form-item .role-box {
            position: relative;
        }

        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

        /***
        *  ztree 图标变成黄色
        */
        .ztree .line {
            line-height: 0;
            border-top: none;
            float: none;
        }

        .ztree li span.button.ico_docu {
            background-position: -110px 0;
            margin-right: 2px;
            vertical-align: top;
        }

        .multiSelect {
            line-height: normal;
            height: auto;
            padding: 4px 10px;
            overflow: hidden;
            min-height: 38px;
            margin-top: -38px;
            left: 0;
            z-index: 99;
            position: relative;
            background: none;
        }

        .multiSelect a {
            padding: 2px 5px;
            background: #908e8e;
            border-radius: 2px;
            color: #fff;
            display: block;
            line-height: 20px;
            height: 20px;
            margin: 2px 5px 2px 0;
            float: left;
        }

        .multiSelect a span {
            float: left;
        }

        .multiSelect a i {
            float: left;
            display: block;
            margin: 2px 0 0 2px;
            border-radius: 2px;
            width: 8px;
            height: 8px;
            background: url(/static/images/close.png) no-repeat center;
            background-size: 65%;
            padding: 4px;
        }

        .multiSelect a i:hover {
            background-color: #545556;
        }

        .layui-field-box a {
            padding: 2px 5px;
            background: #908e8e;
            border-radius: 2px;
            color: #fff;
            display: block;
            line-height: 20px;
            height: 20px;
            margin: 2px 5px 22px 0;
            float: left;
        }

        .layui-field-box a span {
            float: left;
        }

        .boxadd {
            float: left;
            display: block;
            margin: 2px 0 0 2px;
            border-radius: 2px;
            width: 8px;
            height: 8px;
            background-size: 65%;
            padding: 4px;
        }
    </style>
</head>
<body class="childrenBody">
<#--action="/back/content/online/Update"-->
<form class="layui-form" method="post"
      style="width:80%;">
    <input type="hidden" id="contentFreshmanId" name="contentFreshmanId"/>

    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block input-type">
            <input type="radio" id="onlineType0" name="onlineType" value="0" title="自定义内容"/>
            <input type="radio" id="onlineType1" name="onlineType" value="1" title="外部链接"/>
            <input type="radio" id="onlineType2" name="onlineType" value="2" title="添加单页"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="onlineTitle" name="onlineTitle" placeholder="请输入标题">
        </div>
    </div>
    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">内容</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" class="layui-input" id="onlineContent" name="onlineContent" placeholder="请输入内容">-->
        <#--</div>-->
    <#--</div>-->
    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">来源</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" class="layui-input" id="onlineSource" name="onlineSource" placeholder="请输入快讯来源">-->
        <#--</div>-->
    <#--</div>-->

    <div id="type0" class="layui-form-item">
        <input type="hidden" id="onlineDetail" name="onlineDetail">
        <div class="layui-form-item">
            <label class="layui-form-label">详情</label>
            <div class="layui-input-block">
                <textarea id="content" style="display: none;"></textarea>
            </div>
        </div>
    </div>
    <div id="type1" class="layui-form-item">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="onlineLink" name="onlineLink" placeholder="请输入单页链接">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" onclick="update()" lay-filter="addBlogArticle">立即提交</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/wangEditor.min.js"></script>
<script type="text/javascript" src="/static/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/static/js/common.js"></script>
<script>
    var radioValue = 0;
    var layedit = null;
    var content = null;

    layui.use(['element', 'layedit', 'form'], function () {
        var form = layui.form;
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/back/content/an/content/picture/upload',
                type: 'post'
            }
        });
        content = layedit.build('content'); //建立编辑器

        var onlineId = getParam("onlineId");

        function getonline(onlineId) {
            var online;
            $.ajax({
                async: false,
                url: '/back/content/online/search?onlineId=' + onlineId + '',
                type: 'get',
                success: function (baseDto) {
                    dealBaseDto(baseDto, function (baseDto) {
                        online = baseDto.data;
                    })
                }
            });
            return online;
        }

        var online = getonline(onlineId);

        function loadData(online) {
            //设置id
            $("#contentFreshmanId").val(online.id);
            //设置标题
            $("#onlineTitle").val(online.onlineTitle);
            // //设置内容
            // $("#onlineContent").val(online.onlineContent);
            //设置详情
            layedit.setContent(content, online.onlineDetail);
            //设置连接
            $("#onlineLink").val(online.onlineLink);
            // //设置来源
            // $("#onlineSource").val(online.onlineSource);
            if (online.type == 0) {
                $("#type0").show();
                $("#type1").hide();
                $("#onlineType0").attr("checked", "checked");
            } else if (online.type == 1) {
                $("#type0").hide();
                $("#type1").show();
                $("#adLink").attr("placeholder", "请输入外部链接");
                $("#onlineType1").attr("checked", "checked");
            } else if (online.type == 2) {
                $("#type0").hide();
                $("#type1").show();
                $("#adLink").attr("placeholder", "请输入单页链接");
                $("#onlineType2").attr("checked", "checked");
            }
            radioValue = online.type;
            form.render();
        }

        loadData(online);

        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('radio', function (data) {
                if (data.value == 0) {
                    $("#type0").show();
                    $("#type1").hide();
                } else if (data.value == 1) {
                    $("#type0").hide();
                    $("#type1").show();
                    $("#onlineLink").attr("placeholder", "请输入外部链接");
                } else if (data.value == 2) {
                    $("#type0").hide();
                    $("#type1").show();
                    $("#onlineLink").attr("placeholder", "请输入单页链接");
                }
                radioValue = data.value;
            });
        });
    });

    function update() {
        $.ajax({
                url: "/back/content/online/edit",
                type: "post",
                data: {
                    id: $("#contentFreshmanId").val(),
                    onlineTitle: $("#onlineTitle").val(),
                    // onlineContent: $("#onlineContent").val(),
                    onlineDetail: layedit.getContent(content),
                    onlineLink: $("#onlineLink").val(),
                    // onlineSource: $("#onlineSource").val(),
                    type: radioValue
                },
                success: function (data) {
                    alert(data.data);
                    window.location.href = "/back/content/online/listpage";
                }
            }
        );
    }
</script>
</body>
</html>